package p.ithorns.example.statemachine.test;


import p.ithorns.example.statemachine.core.EventEnum;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * FlowEventType
 * 事件枚举
 *
 * @author ithorns
 * @version 1.0.0
 * @date 2022/10/1 21:52
 */
public enum FlowEventType implements EventEnum {

    // 无
    NONE(0, ""),

    // 创建
    CREATE(1, "创建"),

    // 审批
    APPROVE(2, "审批"),

    // 接收
    RECEIVE(3, "接收"),

    // 指派
    ASSIGN(4, "指派"),

    // 完结
    COMPLETE(5, "完结"),

    // 评价
    EVALUATE(6, "评价"),

    ;

    private final int order;

    private final String desc;

    FlowEventType(int order, String desc) {
        this.desc = desc;
        this.order = order;
    }

    public int order() {
        return order;
    }

    public String desc() {
        return desc;
    }

    private final static Map<Integer, FlowEventType> MAP =
            Arrays.stream(FlowEventType.values()).collect(Collectors.toMap(FlowEventType::order, v -> v));

    public static FlowEventType of(Integer status) {
        if (null == status) {
            return NONE;
        }
        return Optional.ofNullable(MAP.get(status))
                .orElse(NONE);
    }


    @Override
    public String getCode() {
        return this.name();
    }

}